package com.leokok.jts.learning.jts.core.dissolve;

import org.junit.Test;
import org.locationtech.jts.dissolve.LineDissolver;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 * 将一组geometry几何分解成一组最大长度的linestring，其中重叠的部分只出现一次
 */
public class LineDissolverTest {

    @Test
    public void test() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry geometry1 = wktReader.read("LINESTRING (0 0, 1 0, 2 1)");
        Geometry geometry2= wktReader.read("LINESTRING (0 0, 1 0, 2 0)");
        Geometry geometry3 = wktReader.read("LINESTRING (1 0, 2 1, 2 0, 3 0)");
        LineDissolver lineDissolver = new LineDissolver();
        lineDissolver.add(geometry1);
        lineDissolver.add(geometry2);
        lineDissolver.add(geometry3);

        Geometry result = lineDissolver.getResult();
        System.out.println(result.toText());
    }
}
